package com.lilin.gps.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lilin.gps.R;
import com.lilin.gps.model.GPSInfo;

public class GPSInfoListAdapter extends BaseAdapter {

    public List<GPSInfo> list;
    Context context;

    public GPSInfoListAdapter(List<GPSInfo> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        LayoutInflater mInflater = LayoutInflater.from(context);
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.gpsinfolist_adapter, null);
            holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle);
            holder.tvPhone = (TextView) convertView.findViewById(R.id.tvPhone);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        GPSInfo info = list.get(position);
        holder.tvTitle.setText(info.GpsTime + " ( " + info.Longitude + " , " + info.Latitude + " ) ");

        if (position % 2 == 0) {
            holder.tvTitle.setTextColor(Color.BLACK);
        } else {
            holder.tvTitle.setTextColor(Color.BLUE);
        }

        return convertView;
    }

    public class ViewHolder {
        public TextView tvTitle;
        public TextView tvPhone;
    }

}
